Understanding (LUNs)

IDL Logical Unit Numbers (LUNs) fall within the range -2 to 128. Some LUNs are reserved for special functions as described below.

The Standard Input, Output, and Error LUNs

The three LUNs described below have special meanings that are operating system dependent:

UNIX

Logical Unit Numbers 0, -1, and -2 are tied to stdin, stdout, and stderr, respectively. This means that the normal UNIX file redirection and pipe operations work with IDL. For example, the shell command

%idl < idl.inp >& idl.out &

will cause IDL to execute in the background, reading its input from the file idl.inp and writing its output to the file idl.out. Any messages sent to stderr are also sent to idl.out.

When using the IDL Workbench, Logical Unit Numbers 0, -1, and -2 are tied to stdin (the command line), stdout (the log window), and stderr (the log window), respectively.

Windows

Logical Unit Numbers 0, -1, and -2 are tied to stdin (the command line), stdout (the log window), and stderr (the log window), respectively.

These special file units are described in more detail below.

File Unit 0

This LUN represents the standard input stream, which is usually the keyboard. Therefore, the IDL statement:

READ, X

is equivalent to the following:

READF, 0, X

File Unit -1

This LUN represents the standard output stream, which is usually the terminal screen. Therefore, the IDL statement:

PRINT, X

is equivalent to the following:

PRINTF, -1, X

File Unit -2

This LUN represents the standard error stream, which is usually the terminal screen.

File Units (1–99)

These are the file units for normal interactive use. When using IDL interactively, the user arbitrarily selects the file units used. The file units from 1 to 99 are available for this use.

File Units (100–128)

These are the file units managed by the GET_LUN and FREE_LUN procedures. If an IDL procedure or function that uses files is written to explicitly use a given file unit, there is a chance that it will conflict with other routines that use the same unit. It is therefore necessary to avoid explicit file unit numbers when writing IDL procedures and functions. The GET_LUN and FREE_LUN procedures provide a standard mechanism for IDL routines to obtain unique file units. GET_LUN allocates a file unit from a pool of free units in the range 100 to 128. This unit will not be allocated again until it is released by a call to FREE_LUN. Meanwhile, it is available for the exclusive use of the program that allocated it. A typical procedure that needs a file unit might be structured as follows:

PRO DEMO

;Get a unique file unit and open the file.

OPENR, UNIT, /GET_LUN

 

;Body of program goes here.

.

.

.

 

;Return file unit.

FREE_LUN, UNIT

 

;Since the file is still open, FREE_LUN will automatically call

;CLOSE.

END

Note: All IDL procedures and functions that open files should use GET_LUN/ FREE_LUN to obtain file units. Furthermore, the file units between 100 and 128 should never be used unless previously allocated by GET_LUN.